#include "../collections.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

node node_create(int T, void * value, node link)
{
	node self = malloc(sizeof(struct node) + T);
	node_write(self, T, value);
	node_connect(self, link);
	return self;
}

node node_delete(node self)
{
	free(self);
	self = NULL;

	return self;
}

void node_write(node self, int T, void * value)
{
	memcpy((void*) self + sizeof(void*), (const void*) (void*) value, T);
}

void node_read(node self, int T, void * value)
{
	memcpy(value, (const void *) (void*) self + sizeof(void*), T);
}

int node_valueis(node self, int T, void * value, comparer comp)
{
	if(comp == NULL)
		return memcmp(value, (const void *) (void*) self + sizeof(void*), T) == 0;
	else
		return comp(value, ((void*) self) + sizeof(void*));
}

void node_connect(node self, node link)
{
	self->link = link;
}


node node_getlink(node self)
{
	return self->link;
}



